﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Slja.Web.Common;
using Slja.BLL.Platform;
using Slja.Model.Platform;

namespace FrameWork.web.Web.Project
{
    public partial class OrderTitle : System.Web.UI.Page
    {
        //string _RoleID;
        public string ViewType
        {
            get { return Request.QueryString["ViewType"]??""; }
        }
        public string RoleID
        {
            set { ViewState["_RoleID"] = value; }
            get { return ViewState["_RoleID"].ToString(); }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Repeater1.ItemDataBound += new RepeaterItemEventHandler(Repeater1_ItemDataBound);
            if (!IsPostBack)
            {
               //
               

                string commonRole = "";
                if (ViewType.ToUpper() == "PUBLIC")
                {
                    commonRole = "-1";//公共角色为-1
                }
                else if (ViewType.ToUpper() == "PRIVATE")
                {
                    commonRole = "-2";//私人角色为-2（表示：我下的订单）
                }
                else
                {
                    UserBLL bll = new UserBLL();
                    UserModel user = bll.GetModel(Common.Get_UserID);
                    commonRole = user.RoleID.ToString();
                }
                XmlDocument xd = XmlDoc.GetOrderListViewDoc();
                XmlNode pnd = xd.SelectSingleNode("/listview/view[@RoleID='" + commonRole + "']");
                if (pnd != null)
                {
                    XmlNodeList children = pnd.ChildNodes;
                    RoleTitle rt = null;
                    List<RoleTitle> titles = new List<RoleTitle>();
                    for (int i = 0; i < children.Count; i++)
                    {
                        rt = new RoleTitle();
                        rt.ParentName = pnd.Attributes["RoleName"].Value;
                        rt.RoleId = commonRole;
                        rt.Title = children[i].Attributes["Caption"].Value;
                        titles.Add(rt);
                    }
                    Repeater1.DataSource = titles;
                    Repeater1.DataBind();
                }

            }
        }

        void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink hpy = e.Item.FindControl("hypLink") as HyperLink;
            if (hpy != null)
            {
                RoleTitle rt = e.Item.DataItem as RoleTitle;
                hpy.NavigateUrl = string.Format("OrderList.aspx?roleid={0}&title={1}&viewtype={2}", rt.RoleId,HttpUtility.UrlEncode(rt.Title),Request.QueryString["ViewType"]);//roleid=<%#bind("RoleID") %>&title=<%# bind("title")%>
            }

        }
       
       
    }
}